package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.service.ImportExcelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author: zyh
 * @date: 2023-07-23
 */
@RestController
@RequestMapping("/excelImport")
@Api(tags = {"A通用模块#excel批量人员进场导入模块"})
public class ImportExcelController {

    @Autowired
    private ImportExcelService importExcelService;

    @WebAccess(login = true)
    @ApiOperation("excel数据校验")
    @PostMapping("/excelDataCheck")
    @ResponseBody
    public WebResponse<Map<String,Object>> excelDataCheck(MultipartFile file) {
        return new WebResponse<>(importExcelService.excelDataCheck(file));
    }

    @WebAccess(login = true)
    @ApiOperation("excel错误信息返回")
    @GetMapping("/excelMessage/{fileId}")
    public void excelMessage(@PathVariable("fileId") String fileId,HttpServletResponse response) {
        importExcelService.excelMessage(fileId,response);
    }

    @WebAccess(login = true)
    @ApiOperation("确认办理入场")
    @GetMapping("/excelImport/{fileId}")
    public WebResponse<Boolean> excelImport(@PathVariable("fileId") String fileId) {
        return new WebResponse<>(importExcelService.excelImport(fileId));
    }

    @WebAccess(login = true)
    @ApiOperation("下载excel导入模板")
    @GetMapping("/downloadExcelTemplate")
    public ResponseEntity<byte[]> downloadExcelTemplate(HttpServletResponse response) {
        return importExcelService.downloadExcelTemplate(response);
    }
}
